package br.com.kees.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.faces.application.NavigationHandler;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JSFUtil {
	
	public static List<SelectItem> ComboSimNao() {
		List<SelectItem> retorno = new ArrayList<SelectItem>();
		retorno.add(new SelectItem("S", "Sim"));
		retorno.add(new SelectItem("N", "Não"));
		return retorno;
	}

	public static HttpServletRequest getRequest() {
		return (HttpServletRequest) getExternalContext().getRequest();
	}
	
	public static HttpServletResponse getResponse() {
		return (HttpServletResponse) getExternalContext().getResponse();
	}
	
	public static void redirecionaPagina(String string) {
		FacesContext fc = FacesContext.getCurrentInstance();
		NavigationHandler nh = fc.getApplication().getNavigationHandler();
		nh.handleNavigation(fc, null, string);
	}
	
	public static void setSessionAttribute(String key, Object value) {
		Map<String, Object> map = getExternalContext().getSessionMap();
		map.put(key, value);
	}
	
	public static ExternalContext getExternalContext() {
		FacesContext fc = FacesContext.getCurrentInstance();
		return fc.getExternalContext();
	}
	

}
